/*
 * $Id: SkvListPath.h,v 1.4 2006-04-24 08:42:10 bacon Exp $
 */

#ifndef _XPP_UTL_SKVLISTPATH_CLASS_
#define _XPP_UTL_SKVLISTPATH_CLASS_

#include <xpp/utl/SkvList.h>
#include <xpp/sys/Path.h>
#include <xp/bas/sio.h>

namespace xpp
{
	namespace utl
	{

		class SkvListPath: public xpp::sys::Path
		{
		public:
			SkvListPath () 
			{
				error_code = ERR_NONE;
				error_line = 0;
			}
		
			SkvListPath (const xp_char_t* p): xpp::sys::Path(p) 
			{
				error_code = ERR_NONE;
				error_line = 0;
			}
		
			enum 
			{
				ERR_NONE       = 0,
				ERR_SYSTEM     = 1,
				ERR_NOLABEL    = 2, 
				ERR_WRONGLABEL = 3, 
				ERR_NOID       = 4
			};
		
			xp_size_t errorLine () const 
			{
				return error_line;
			}
			int errorCode () const 
			{
				return error_code;
			}
			xp_char_t* getErrorStr (xp_char_t* buf, xp_size_t count) const;	
		
			int read  (SkvList* skv);
			int write (SkvList* skv, bool append = false);
			int write (SkvList* skv, const xp_char_t* file, bool append = false);
		
		protected:
			int    error_code;
			xp_size_t error_line;
		
		private:
			int parse_section_line (
				xp_sio_t* sio, xp_str_t* line, SkvList* skv);
			int parse_pair_line (xp_str_t* line, SkvSctn* sctn);
		
			xp_char_t* get_label (xp_str_t* line);
			int is_label   (const xp_str_t* line);
			int is_comment (const xp_str_t* line);
			int read_line  (xp_sio_t* sio, xp_str_t* line);
		};

	}
}
		
#endif
		
